package com.xunyin.modules.storeroom.service.mapper;

import com.xunyin.common.mapper.CoreMapper;
import com.xunyin.modules.shareorder.service.dto.ShareCountDto;
import com.xunyin.modules.storeroom.domain.TStoreRoom;
import com.xunyin.modules.storeroom.vo.TStoreRoomAsChildVo;
import com.xunyin.modules.storeroom.vo.TStoreRoomVo;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author admin
 * @date 2022-09-19
 */
@Repository
public interface TStoreRoomMapper extends CoreMapper<TStoreRoom> {

    @Select("SELECT (SELECT COUNT(1) FROM t_share_order WHERE store_room_id = stc.id and status=1 " +
            " AND (order_status = 1 or order_status = 2 or order_status = 4)) as sold,  " +
            " stc.id AS teaChildId,stc.store_room_name AS teaChildName,stc.price,stc.recommended,stc.icon AS teaChildImages," +
            " stc.status AS teaChildStatus" +
            "  FROM t_store_room stc " +
            " WHERE  stc.store_id = #{storeId} and stc.is_del=0")
    List<TStoreRoomAsChildVo> getStoreRooms(@Param("storeId") Integer id);


    @Select("SELECT stc.id AS teaChildId,stc.store_id as storeId,stc.store_room_name AS teaChildName,stc.price, stc.recommended, " +
            " stc.icon AS teaChildImages,stc.images as imagesContentArray,  " +
            " (SELECT COUNT(1) " +
            " FROM t_share_order " +
            " WHERE store_room_id = stc.id " +
            " and status=1 " +
            " AND (order_status = 1 or order_status = 2 or order_status = 4)) as sold, " +
            " st.name,st.address,st.longitude,st.latitude,st.phone,stc.status AS teaChildStatus,st.main_id as mainId " +
            "  FROM t_store_room stc " +
            " LEFT JOIN t_store st ON stc.store_id = st.id " +
            " WHERE stc.id = #{id} AND stc.status = 1 ")
    TStoreRoomVo getInfoTeaChild(@Param("id") Integer id);


    @Select("SELECT t2.store_room_name as roomName from t_share_order t1 " +
            "LEFT JOIN t_store_room t2 on t1.store_room_id=t2.id " +
            "where t1.order_status in (0,1,2,4) ")
    List<ShareCountDto> findRoomName();

}
